//
//  IDOLeadingPageCell.m
//  IDOLeadingPageController
//
//  Created by 卓勇  on 2017/6/1.
//  Copyright © 2017年 zhuoyong. All rights reserved.
//

#import "IDOLeadingPageCell.h"

@implementation IDOLeadingPageCell

#pragma mark - init
- (instancetype)init {
    self = [super init];
    
    if (self) {
        [self commonInit];
    }
    
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    
    if (self) {
        [self commonInit];
    }
    
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    
    if (self) {
        [self commonInit];
    }
    
    return self;
}

- (void)commonInit {
    [self.contentView addSubview:self.imageView];
    [self.contentView addSubview:self.finishButton];
}

#pragma mark - layoutSubviews
- (void)layoutSubviews {
    [super layoutSubviews];
    
    // 调整图片视图大小
    self.imageView.frame = self.contentView.bounds;
    
    // 调整按钮视图大小
    [self.finishButton sizeToFit];
    CGFloat finishButtonWidth = self.finishButton.bounds.size.width + 30.f;
    CGFloat finishButtonHeight = self.finishButton.bounds.size.height;
    CGFloat finishButtonX = (self.contentView.bounds.size.width - finishButtonWidth) / 2.0;
    CGFloat finishButtonY = self.contentView.bounds.size.height - finishButtonHeight - 100.f;
    self.finishButton.frame = CGRectMake(finishButtonX, finishButtonY, finishButtonWidth, finishButtonHeight);
    self.finishButton.layer.cornerRadius = finishButtonHeight / 2.0;
}


#pragma mark - button click
- (void)finishButtonClick:(UIButton *)sender {
    if (self.finishButtonClickBlock) {
        self.finishButtonClickBlock(sender);
    }
}

#pragma mark - getter
- (UIImageView *)imageView {
    if (!_imageView) {
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.contentMode = UIViewContentModeScaleToFill;
        _imageView = imageView;
    }
    return _imageView;
}

- (UIButton *)finishButton {
    if (!_finishButton) {
        UIButton *finishButton = [UIButton buttonWithType:UIButtonTypeCustom];
        finishButton.backgroundColor = [UIColor yellowColor];
        finishButton.layer.masksToBounds = YES;
        [finishButton addTarget:self action:@selector(finishButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        _finishButton = finishButton;
    }
    return _finishButton;
}

@end
